package com.bed.lovewithpatientbed.controller;

import com.bed.lovewithpatientbed.common.bean.LayUiPageBean;
import com.bed.lovewithpatientbed.core.annocation.LogAnno;
import com.bed.lovewithpatientbed.pojo.FeedBackBean;
import com.bed.lovewithpatientbed.pojo.Feedback;
import com.bed.lovewithpatientbed.service.FeedBackService;
import com.bed.lovewithpatientbed.util.LayUiUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tyl
 * @version 1.0.0
 * @ClassName FeedBackController.java
 * @Description TODO
 * @createTime 2020年10月20日 14:40:00
 */
@Controller
@RequestMapping("feedback")
public class FeedBackController {
    @Autowired
    FeedBackService feedBackService;
    /**
     * @description 跳转页面
     * @author tyl
     * @updateTime 2020/10/20 14:44 
     * @param
     */
    @RequestMapping("list")
    public String list(){
        return "feedback/list";
    }
    @RequestMapping("listDo")
    @ResponseBody
    /**
     * @description 按条件查所有
     * @author tyl
     * @updateTime 2020/10/20 14:45
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     * @param  pageBean:分页;startTime:最小时间;maxTime:最大时间
     */
    public Map<String,Object> listDo(LayUiPageBean pageBean, String minTime, String maxTime) throws ParseException {
        List<Feedback> feedBackServiceList = feedBackService.selecByExample(pageBean,minTime,maxTime);
        System.out.println(feedBackServiceList.size());
        Integer count = feedBackService.selectCount( pageBean,  minTime,  maxTime);
        List<FeedBackBean> feedBackBeanList = new ArrayList<>();
        for (Feedback f :feedBackServiceList) {
            FeedBackBean feedBackBean = new FeedBackBean();
            feedBackBean.setFeedbackId(f.getFeedbackId());
            feedBackBean.setFeedbackMessage(f.getFeedbackMessage());
            feedBackBean.setFeedbackTime(f.getFeedbackTime());
            feedBackBean.setUserNickname(f.getUser().getUserNickname());
            feedBackBean.setUserId(f.getUser().getUserId());
            feedBackBeanList.add(feedBackBean);
        }
        return LayUiUtil.getLayTableResponseMap("success",0,count,feedBackBeanList);
    }
    /*增加*/
    @LogAnno(operateType = "添加反馈")
    @RequestMapping("insert")
    @ResponseBody
    public String insertFeedBackMessage(Feedback feedBack) {
        feedBackService.insertFeedBackMessage(feedBack);
        return "success";
    }
    /*删除*/
    @LogAnno(operateType = "删除反馈")
    @RequestMapping("delete")
    @ResponseBody
    public String deleteFeedBack(Integer feedbackId) {
        feedBackService.deleteFeedBack(feedbackId);
        return "success";
    }
    /*查一个*/
    @RequestMapping("selectOne")
    @ResponseBody
    public Map<String,Object> selectOne(Integer userId) {
        Map<String,Object> maps = new HashMap<>();
        Feedback feedback = feedBackService.selectOne(userId);
        maps.put("feedback",feedback);
        return maps;
    }
}
